import router from '@/router';

import { onMounted, reactive, ref, watch } from 'vue';
import { purmamPage } from '@api/url/test';
import { getInitParam, queryDataFilter } from '@utils/baseMethods';
import { queryUnit } from '@api/url/equipmentManagement';

export default function importConfig() {
  const data = ref([]);

  const base = reactive<any>({
    size: 'medium',
    columns: [
      {
        title: '设备类型编码',
        dataIndex: 'code',
        checked: true,
      },
      {
        title: '设备类型名称',
        dataIndex: 'name',
        checked: true,
      },
      {
        title: '是否启用',
        slotName: 'status',
        checked: true,
      },
      {
        title: '备注',
        dataIndex: 'descr',
        checked: true,
      },
      {
        title: '操作',
        slotName: 'option',
        checked: true,
      },
    ],
    searchConfig: null,
    config: ['add', 'update', 'del', 'derive'],
    pagination: {
      defaultPageSize: 10,
      total: 1, //总条数
      current: 1,
      pageSize: 10,
      showTotal: true,
      showPageSize: true,
      pageSizeOptions: [10, 20, 30, 40, 50],
    },
    editVisible: false,
    showSearchBar: true,
    searchBar: '隐藏搜索',
  });

  const collection = reactive([
    { label: '设备类型名称', value: '', key: 'COMPANY', placeholder: '请输入设备类型名称', isInput: true },
    { label: '是否启用', value: '', key: 'MA013', placeholder: '选择是或否', isSelect: true, options: ['是', '否'] },
  ]);

  // /**
  //  * @exports searchConfig 搜索栏配置表
  //  */
  // const searchConfig = () => {
  //   return [
  //     {
  //       label: '公司名称',
  //       key: 'COMPANY',
  //       placeholder: '请输入公司名称',
  //       value: null,
  //     },
  //     {
  //       label: '创建人',
  //       key: 'CREATOR',
  //       placeholder: '请输入创建人',
  //       value: null,
  //     },
  //     {
  //       label: '供应商ID',
  //       key: 'MA001',
  //       placeholder: '请输入供应商ID',
  //       value: null,
  //     },
  //     {
  //       label: '供应商名称',
  //       key: 'MA003',
  //       placeholder: '请输入供应商名称',
  //       value: null,
  //     },
  //     {
  //       label: '负责人',
  //       key: 'MA011',
  //       placeholder: '请输入供应商负责人',
  //       value: null,
  //     },
  //     {
  //       label: '负责人号码',
  //       key: 'MA011',
  //       placeholder: '请输入供应商负责人的手机号',
  //       value: null,
  //     },
  //   ];
  // };

  const getTableData = (flag: string) => {
    const obj = {
      id: null,
      name: collection[0].value,
      status: collection[1].value == '是' ? 1 : 0,
    };
    queryUnit(obj).then((res) => {
      if (res.code == 200) {
        data.value = res.data;
        console.log('赋值的数据', data.value);
      }
    });
  };

  const tapDate = () => {
    getTableData('search');
  };

  const edit = () => {
    base.editVisible = true;
  };

  const add = () => {
    base.editVisible = true;
  };

  const del = () => {
    base.editVisible = true;
  };

  //控制搜索框的显示与隐藏
  const changeSearchBar = () => {
    base.showSearchBar = !base.showSearchBar;
    if (base.showSearchBar) {
      base.searchBar = '隐藏搜索';
    } else {
      base.searchBar = '显示搜索';
    }
  };

  onMounted(() => {
    getTableData();
  });

  return {
    base,
    collection,
    data,
    tapDate,
    edit,
    add,
    del,
    changeSearchBar,
  };
}
